﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Sizebox.CharacterEditor
{
	// Token: 0x0200023A RID: 570
	public class BaseView : MonoBehaviour
	{
		// Token: 0x06000C35 RID: 3125 RVA: 0x0006408C File Offset: 0x0006228C
		protected virtual void Awake()
		{
			this.Controller = Camera.main.GetComponent<InterfaceControl>();
			this.Controller.OnSelected += this.OnSelection;
			if (this.subViews == null)
			{
				this.subViews = new List<ViewConfig>();
			}
			for (int i = 0; i < this.subViews.Count; i++)
			{
				if (this.subViews[i].activator)
				{
					if (this.subViews[i].activator as Button)
					{
						ViewConfig viewConfig = this.subViews[i];
						Button button = this.subViews[i].activator as Button;
						(viewConfig.activator as Button).onClick.AddListener(delegate()
						{
							this.OnButtonClick(viewConfig, button);
						});
					}
					else if (this.subViews[i].activator as Toggle)
					{
						ViewConfig viewConfig = this.subViews[i];
						Toggle toggle = this.subViews[i].activator as Toggle;
						(viewConfig.activator as Toggle).onValueChanged.AddListener(delegate(bool value)
						{
							this.OnToggleClick(value, viewConfig, toggle);
						});
					}
				}
			}
		}

		// Token: 0x06000C36 RID: 3126 RVA: 0x00002973 File Offset: 0x00000B73
		protected void Start()
		{
		}

		// Token: 0x06000C37 RID: 3127 RVA: 0x0006421C File Offset: 0x0006241C
		protected void OnToggleClick(bool value, ViewConfig viewConfig, Toggle toggle)
		{
			BaseView view = viewConfig.view;
			if (value)
			{
				if (this.disableOtherSubViews)
				{
					foreach (ViewConfig viewConfig2 in this.subViews)
					{
						viewConfig2.view.gameObject.SetActive(false);
					}
				}
				view.gameObject.SetActive(true);
				viewConfig._OpenEvent();
			}
			else if (viewConfig.activatorIsToggle)
			{
				view.gameObject.SetActive(false);
			}
			else
			{
				toggle.isOn = true;
			}
		}

		// Token: 0x06000C38 RID: 3128 RVA: 0x000642D4 File Offset: 0x000624D4
		protected void OnButtonClick(ViewConfig viewConfig, Button button)
		{
			BaseView view = viewConfig.view;
			if (view.gameObject.activeSelf && viewConfig.activatorIsToggle)
			{
				view.gameObject.SetActive(false);
			}
			else if (!view.gameObject.activeSelf)
			{
				if (this.disableOtherSubViews)
				{
					this.DisableAllSubViews();
				}
				view.gameObject.SetActive(true);
				viewConfig._OpenEvent();
				if (viewConfig.disableInteractionOnClick)
				{
					button.interactable = false;
				}
			}
		}

		// Token: 0x06000C39 RID: 3129 RVA: 0x00002973 File Offset: 0x00000B73
		protected virtual void OnEnable()
		{
		}

		// Token: 0x06000C3A RID: 3130 RVA: 0x0006435C File Offset: 0x0006255C
		protected virtual void OnDisable()
		{
			if (this.disableSubViewsOnDisable)
			{
				foreach (ViewConfig viewConfig in this.subViews)
				{
					viewConfig.view.gameObject.SetActive(false);
				}
			}
		}

		// Token: 0x06000C3B RID: 3131 RVA: 0x000643D0 File Offset: 0x000625D0
		protected virtual void OnSelection()
		{
			if (base.isActiveAndEnabled)
			{
				this.OnEnable();
			}
		}

		// Token: 0x06000C3C RID: 3132 RVA: 0x000643E4 File Offset: 0x000625E4
		protected void DisableAllSubViews()
		{
			foreach (ViewConfig viewConfig in this.subViews)
			{
				if (viewConfig.disableInteractionOnClick)
				{
					viewConfig.activator.interactable = true;
				}
				viewConfig.view.gameObject.SetActive(false);
			}
		}

		// Token: 0x06000C3D RID: 3133 RVA: 0x00064464 File Offset: 0x00062664
		protected void RegisterForViewEnabled(BaseView view, Action callback)
		{
			int subViewIndex = BaseView.GetSubViewIndex(this.subViews, view);
			if (subViewIndex == -1)
			{
				return;
			}
			this.subViews[subViewIndex].OnViewOpen += callback.Invoke;
		}

		// Token: 0x06000C3E RID: 3134 RVA: 0x000644A4 File Offset: 0x000626A4
		private static int GetSubViewIndex(List<ViewConfig> subviews, BaseView view)
		{
			for (int i = 0; i < subviews.Count; i++)
			{
				if (subviews[i].view == view)
				{
					return i;
				}
			}
			return -1;
		}

		// Token: 0x04001169 RID: 4457
		[SerializeField]
		[Header("View Settings")]
		protected List<ViewConfig> subViews = new List<ViewConfig>();

		// Token: 0x0400116A RID: 4458
		[SerializeField]
		private bool disableOtherSubViews = true;

		// Token: 0x0400116B RID: 4459
		[SerializeField]
		private bool disableSubViewsOnDisable;

		// Token: 0x0400116C RID: 4460
		protected InterfaceControl Controller;
	}
}
